package com.itsu.integration;

import io.github.resilience4j.ratelimiter.RateLimiterConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;

import java.time.Duration;

@SpringBootApplication
@ImportResource(locations = {"classpath:spring-integration.xml"})
//@ImportResource(locations = {"classpath:servlet-config.xml"})
public class IntegrationApplication {

    public static void main(String[] args) {
        SpringApplication.run(IntegrationApplication.class, args);
    }

//    @Bean
//    @DependsOn("marshaller")
//    public WsClient wsClient(Jaxb2Marshaller marshaller) {
//        WsClient client = new WsClient();
//        client.setDefaultUri("http://localhost:8111/ws/countries");
//        client.setMarshaller(marshaller);
//        client.setUnmarshaller(marshaller);
//        return client;
//    }

    /**
     * 限流设定周期为5秒，单周期内允许的最大请求为2次，超时时间为1秒
     *
     * @return
     */
    @Bean
    public RateLimiterConfig rateLimiterConfig() {
        return RateLimiterConfig.custom()
                .limitRefreshPeriod(Duration.ofSeconds(5))
                .limitForPeriod(2)
                .timeoutDuration(Duration.ofSeconds(1))
                .build();
    }

}
